package districting;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Bitmap {

   public static void createBitmap(int width, int height, Colorable[][] array,
         String filename) throws IOException {

      BufferedImage img = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);
      for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
            Color c;
            if (array[x][y] != null) {
               c = array[x][y].getColor();
            } else {
               c = Color.white;
            }
            img.setRGB(x, height - 1 - y, c.getRGB());
         }
      }

      ImageIO.write(img, "bmp", new File(filename));

   }

}
